**JPART Conflict Contagion: McLaughlin, Mewhirter, Lubell 
**note: spatial models require reading in the "W" matrices separate from the data
**note: lagrange multiplier tests require the W matrices to match exactly the number of observations as the data
*** i.e., unlike the SAR models, Stata cannot "force" the LM test if there is a mismatch between matrix and data
**** hence, forums with missng data that were elimianted from SAR models were hand removed from matrix to run LM tests


**collapsing at forum level and prepping for CA Delta for SAR models

clear
set more off
use "/Users/daniellemclaughlin/Desktop/FINALCOMBINED_FROMJACK.DTA"
drop if paranadum==1
drop if tampadum==1

collapse conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science, by(forumid)
drop if forumid==.


//save data to run SAR models subsequently 

**collapsing at forum level and prepping for Tampa for SAR models

clear
set more off
use "/Users/daniellemclaughlin/Desktop/FINALCOMBINED_FROMJACK.DTA"
drop if paranadum==1
drop if calidum==1

collapse conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science, by(forumid)
drop if forumid==.

//save data to run SAR models subsequently 

**CA SAR models with two W's: comember and euc issue

*read in comember W 

clear
set more off
use "/Users/daniellemclaughlin/Desktop/W_Cali_Forums_Prop.dta"
gen id = _n
spset id 

spmatrix fromdata W= participation*, normalize(spectral) replace  
spmatrix summarize W

*read in euc issue W 

use "/Users/daniellemclaughlin/Desktop/W_Cali_Euc.dta", clear
gen id=_n
spset id

spmatrix fromdata E=part*, normalize(spectral) replace
spmatrix summarize E

**read in regular data 

use "/Users/daniellemclaughlin/Desktop/cali.dta", clear
gen id = _n
spset id 

spregress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science, gs2sls dvarlag(W) dvarlag(E) force  
regress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science

**Tampa SAR models with two W's: comember and euc issue

*read in comember W 

clear
set more off
use "/Users/daniellemclaughlin/Desktop/W_Tampa_Forums_Prop.dta"
gen id = _n
spset id 

spmatrix fromdata W = participation*, normalize(spectral) replace 
spmatrix summarize W

*read in euc issue W 

use "/Users/daniellemclaughlin/Desktop/W_Tampa_Euc.dta", clear
gen id=_n
spset id

spmatrix fromdata E=part*, normalize(spectral) replace
spmatrix summarize E

**read in regular data 

use "/Users/daniellemclaughlin/Desktop/tampa.dta", clear
gen id = _n
spset id 

spregress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science, gs2sls dvarlag(W) dvarlag(E) force  
regress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science




*****Lagrange multiplier and moran I tests
**note: lagrange multiplier tests require the W matrices to match exactly the number of observations as the data
*** i.e., unlike the SAR models, Stata cannot "force" the LM test if there is a mismatch between matrix and data
**** hence, forums with missng data that were elimianted from SAR models were hand removed from matrix to run LM tests



//regress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science


**Cali
clear 
set more off
spatwmat using "/Users/daniellemclaughlin/Desktop/W_Cali_LM:Moran.dta", name(camoran) standardize eigenval(I)

use "/Users/daniellemclaughlin/Desktop/FINALCOMBINED_FROMJACK.DTA"
drop if paranadum==1
drop if tampadum==1

collapse conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science, by(forumid)
drop if forumid==.
drop if conflforum==.
drop if efficforum==.
drop if impactforum==.
drop if govtype==.
drop if forumcount==.
drop if forumsize==.
drop if gv==.
drop if experience==.
drop if reqforum==.
drop if science==.

list forumid if forumid==.
list forumid if conflforum==.
list forumid if efficforum==.
list forumid if impactforum==.
list forumid if govtype==.
list forumid if forumcount==.
list forumid if forumsize==.
list forumid if gv==.
list forumid if experience==.
list forumid if reqforum==.
list forumid if science==.

regress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science
**LM
spatdiag, weights(camoran)

**moran
spatgsa conflforum, w(camoran) m two




**Tampa
clear 
set more off

spatwmat using "/Users/daniellemclaughlin/Desktop/W_Tampa_LM:Moran.dta", name(tampamoran) standardize eigenval(I)

use "/Users/daniellemclaughlin/Desktop/FINALCOMBINED_FROMJACK.DTA"
drop if paranadum==1
drop if calidum==1

collapse conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science, by(forumid)
drop if forumid==.
drop if conflforum==.
drop if efficforum==.
drop if impactforum==.
drop if govtype==.
drop if forumcount==.
drop if forumsize==.
drop if gv==.
drop if experience==.
drop if reqforum==.
drop if science==.

list forumid if forumid==.
list forumid if conflforum==.
list forumid if efficforum==.
list forumid if impactforum==.
list forumid if govtype==.
list forumid if forumcount==.
list forumid if forumsize==.
list forumid if gv==.
list forumid if experience==.
list forumid if reqforum==.
list forumid if science==.

regress conflforum experience govtype forumcount forumsize gv efficforum impactforum reqforum science
**LM
spatdiag, weights(tampamoran)

**moran
spatgsa conflforum, w(tampamoran) m two

















